/**
 *
 * 版权所有 © cybersky.com
 *
 */
package cn.cybertron.primus.report.data;

import cn.cybertron.primus.report.entity.ReportCache;

/**
 * 中间表统计类型
 * @author ch
 * 五分钟统计，小时统计，天统计
 */
public class ReportStageType {

	public static final ReportStageType FIVEMINUTES_STAGE = new ReportStageType("5minutely", 5, 1500, "0 0/5 * * * ?");
	
	public static final ReportStageType HOURLY_STAGE = new ReportStageType("hourly", 60, 11520/* 8天 */, "0 0 * * * ?");
	
	public static final ReportStageType DAILY_STAGE = new ReportStageType("daily", 1440, -1, "0 0 0 * *  ?");

	protected String name;

	/**
	 * 统计间隔，单位分钟
	 */
	protected int interval;
	
	/**
	 * 最大存储时长，单位分钟
	 * -1 表示永不删除
	 */
	protected int storage;
	
	/**
	 * 统计时刻，cron字符串
	 */
	protected String fireTime;
	
	/**
	 * 统计所对应的中间表表名
	 * 系统内置中间表该字段为空
	 */
	protected String cacheName;

	public ReportStageType() {
		this.name = "5minutely";
		this.interval = 5;
		this.storage = 1500;//25小时
		this.fireTime = "0 0/5 * * * ?";
	}
	
	public ReportStageType(ReportCache cache) {
		this.name = "5minutely";
		this.interval = cache.getIntervalTime();
		this.storage = cache.getStorageTime();
		this.fireTime = "0 0/"+ this.interval +" * * * ?";
	}
	
	public ReportStageType(String name, int interval, int storage, String fireTime) {
		this.name = name;
		this.interval = interval;
		this.storage = storage;
		this.fireTime = fireTime;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((fireTime == null) ? 0 : fireTime.hashCode());
		result = prime * result + interval;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + storage;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ReportStageType other = (ReportStageType) obj;
		if (fireTime == null) {
			if (other.fireTime != null)
				return false;
		} else if (!fireTime.equals(other.fireTime))
			return false;
		if (interval != other.interval)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (storage != other.storage)
			return false;
		if (cacheName == null) {
			if (other.cacheName != null)
				return false;
		} else if (!cacheName.equals(other.cacheName))
			return false;
		return true;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getInterval() {
		return interval;
	}

	public void setInterval(int interval) {
		this.interval = interval;
	}

	public int getStorage() {
		return storage;
	}

	public void setStorage(int storage) {
		this.storage = storage;
	}

	public String getFireTime() {
		return fireTime;
	}

	public void setFireTime(String fireTime) {
		this.fireTime = fireTime;
	}

	public String getCacheName() {
		return cacheName;
	}

	public void setCacheName(String cacheName) {
		this.cacheName = cacheName;
	}
	
}
